package com.hotelvip.controller;

import com.hotelvip.common.utils.JSONResult;
import com.hotelvip.dto.VipUserDTO;
import com.hotelvip.entity.VipUser;
import com.hotelvip.service.VipUserService;
import com.hotelvip.vo.VipInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description vip用户模块
 * @author ypb
 * @time 2021-1-8 15:05:58
 */
@RestController
@RequestMapping("/vipUser")
@Api(basePath = "vipUser", tags = "vip客户用户模块")
public class VipUserController {

    @Autowired
    private VipUserService vipUserService;



    /**
     * 会员新增
     * 会员新增vip卡套餐
     * @param vipUserDTO 会员卡类型
     * @return
     */

    @ApiOperation(value = "普通用户升级会员/会员新增vip套餐", httpMethod = "POST")
    @PostMapping("/saveVipUser")
    public JSONResult saveVipUser(@RequestBody VipUserDTO vipUserDTO) {
        vipUserService.saveVipUser(vipUserDTO);
        return JSONResult.ok();
    }

    /**
     * 用户升级VIP回显用户信息
     */
    @ApiOperation(value = "用户信息的回显", httpMethod = "GET")
    @GetMapping("/findByUser/{userId}")
    public JSONResult findByUserId(@PathVariable("userId") Long userId) {
        return JSONResult.ok(vipUserService.findByUserId(userId));
    }


    @ApiOperation(value = "Vip用户列表查询", httpMethod = "GET")
    @GetMapping("/findAllVipUsers")
    public JSONResult findAllVipUsers(
            @ApiParam(value = "搜索关键字", required = false)  @RequestParam(value = "key", required = false) String key,
            @ApiParam(value = "当前页码", required = true) @RequestParam(value = "current",defaultValue = "1") Integer page,
            @ApiParam(value = "每页大小", required = true) @RequestParam(value = "size",defaultValue = "20") Integer rows,
            @ApiParam(value = "手机号码", required = false) @RequestParam(value = "phoneNum", required = false) String phoneNum
    ) {

        return JSONResult.ok(vipUserService.queryVipUserByPage(key, page,rows,phoneNum));
    }


    /**
     * 根据vip用户的id查询此用户下所有的vip卡的信息
     * @param userId
     * @return
     */
    @ApiOperation(value = "查看用户的会员卡信息", httpMethod = "GET")
    @GetMapping("/findVipCardByUserId/{userId}")
    public JSONResult findVipCardByUserId(@PathVariable("userId") Long userId) {
        return JSONResult.ok(vipUserService.findVipCardByUserId(userId));
    }
    /**
     *vip用户的删除并不是真的删除,而是修改用户的状态,完成假删除操作
     * 保留此用户的使用数据
     * 注销用户前保证用户的会员卡中没有可使用的权益
     */
    @ApiOperation(value = "注销用户", httpMethod = "PUT")
    @PutMapping("/deleteUserByUserId")
    public JSONResult deleteVipUserById(Long userId)
             {
        vipUserService.deleteVipUserById(userId);
        return JSONResult.ok();
    }


    @ApiOperation(value = "更新会员卡",httpMethod = "POST")
    @PostMapping("/doUpdateVipStatus")
    public JSONResult doUpdateVipStatus(
            @ApiParam(value = "绑定会员卡id",required = true) @RequestParam(value = "id") Long id,
            @ApiParam(value = "需要修改的状态：-1删除 2激活 3 注销",required = true) @RequestParam(value = "status") Integer status){
        vipUserService.doUpdateVipStatus(id,status);
        return JSONResult.ok("修改成功");
    }
    @ApiOperation(value = "修改会员信息",httpMethod = "POST")
    @PostMapping("/doUpdateVip")
    public JSONResult doUpdateVip(@RequestBody VipUser vipUser){
        vipUserService.updateById(vipUser);
        return JSONResult.ok("更新完成");
    }

    @ApiOperation(value = "获取vip用户商品信息",httpMethod = "POST")
    @PostMapping("/getVitem")
    public JSONResult getVitem(@RequestBody VipUserDTO vipUserDTO){
        return JSONResult.ok(vipUserService.getVitem(vipUserDTO));
    }

    @ApiOperation(value = "查询会员以及会员所绑定的卡",httpMethod = "GET")
    @GetMapping("/getVipInfo")
    public JSONResult getVipInfo(@ApiParam(value = "模糊搜索,可对姓名 微信 电话 身份证号 会员卡号进行模糊查询",required = false)
                                     @RequestParam(value = "id") String key){
        List<VipInfoVo> vipInfoVos = vipUserService.getVipInfo(key);
        return JSONResult.ok(vipInfoVos);
    }
}
